<%--
  Created by IntelliJ IDEA.
  User: 92329
  Date: 2018/4/23
  Time: 11:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="common.jspf"%>
<html>
<head>
    <title>文章发布</title>
    <script src="${hkxyPath}/resources/ckeditor/ckeditor.js"></script>
    <script src="${hkxyPath}/resources/ckeditor/config.js"></script>
    <script>
        $(function(){
        });
        function ajaxSubmit(data){
            for(instance in CKEDITOR.instances){
                CKEDITOR.instances[instance].updateElement();
            }
            var formData = new FormData($("#form")[0]);
            $.ajax({
                type: "POST",
                dataType: "json",//预期服务器返回的数据类型
                url: "${hkxyPath}/${type}/do-publish?state="+data+"&method=0",
                data: formData,
                contentType: false,    //这个一定要写
                processData: false, //这个也一定要写，不然会报错
                success: function (result) {
                    if(result.code==1){
                        tips(1);
                        setTimeout(function(){
                            $("#main").load("${hkxyPath}/${type}/manage",null,null);
                            history.pushState(null,null,"${hkxyPath}/${type}/manage")
                        },2000);
                    }else {
                        console.log("error \n"+result.message);
                        tips(0)
                    }
                }
            })
        }
        function imgPreview(obj,img) {
            var imgid="#"+img;
            var pic=obj.files[0];
            var reader=new FileReader();
            reader.readAsDataURL(pic);
            reader.onload=function (e) {
                $(imgid).attr("src",this.result).show();
            }
        }
    </script>
</head>
<body>
<div id="writeMain">
    <%@include file="tips.jspf"%>
    <div style="height: 60px">
        <h2>内容发布</h2>
    </div>

    <form id="form" role="form" class="padding-5"
    <%--action="${hkxyPath}/do-${type}-publish" method="post"--%>
          enctype="multipart/form-data">
        <div class="form-group">
            <label for="name" class="input-control input-control-title padding-b-5">题目</label>
            <input name="title" type="text" class="form-control" maxlength="30" id="name" placeholder="请输入题目，30个字符以内">
        </div>
        <div class="form-group">
            <label for="name" class="padding-b-5">内容</label>
            <textarea class="form-control" name="content" id="content" style="height: 500px"></textarea>
            <script type="text/javascript">
                editor=CKEDITOR.replace('content',{
                    height:300,
                    filebrowserImageUploadUrl:'${hkxyPath}/upload/image',
                    language : 'zh-cn'
                });
            </script>
        </div>
        <div class="form-group inline-form">
            <label for="inputfile" class="padding-b-5">设置封面</label>
            <div class="preview-img">
                <img src="" id="preview-img" class="imgpreview">
            </div>
            <input type="file" id="inputcover" name="cover" onchange="imgPreview(this,'preview-img')">
        </div>
        <div class="form-group inline-form">
            <label for="inputfile" class="padding-b-5">附件上传</label>
            <input type="file" id="inputfile" name="file">
            <span class="help-block">如有需要可进行文件上传，并在前台提供下载功能。</span>
        </div>
        <div class="inline-form text-right">
            <button type="button" name="state" class="btn btn-info btn-lg" value="1" onclick="ajaxSubmit(1)">发布</button>
            <button type="button" name="state" value="0" class="btn btn-default btn-lg" onclick="ajaxSubmit(0)">存草稿</button>
        </div>
    </form>
</div>
</body>
</html>
